package ext

import (
	"hundsun.com/hsl/hschain/common/log"
	"hundsun.com/hsl/hschain/contract/evm/ext/common"
)

// EvmLog 合约在日志，对应EVM中的Log指令，可以生成指定的日志信息
type EvmLog struct {
	// Consensus fields:
	// address of the contract that generated the event
	Address common.Address `json:"address" gencodec:"required"`
	// list of topics provided by the contract.
	Topics []common.Hash `json:"topics" gencodec:"required"`
	// supplied by the contract, usually ABI-encoded
	Data []byte `json:"data" gencodec:"required"`

	// Derived fields. These fields are filled in by the node
	// but not secured by consensus.
	// block in which the transaction was included
	BlockNumber uint64 `json:"blockNumber"`
	// hash of the transaction
	TxHash common.Hash `json:"transactionHash" gencodec:"required"`
	// index of the transaction in the block
	TxIndex uint `json:"transactionIndex"`
	// hash of the block in which the transaction was included
	BlockHash common.Hash `json:"blockHash"`
	// index of the log in the block
	Index uint `json:"logIndex"`

	// The Removed field is true if this log was reverted due to a chain reorganisation.
	// You must pay attention to this field if you receive logs through a filter query.
	Removed bool `json:"removed"`
}

// PrintLog 合约日志打印格式
func (l *EvmLog) PrintLog() {
	log.Debugf("Evm Log contract address %s, index %d, topics %v, log data %s", l.Address.String(), l.Index, l.Topics, common.Bytes2Hex(l.Data))
}
